package com.cskaoyan.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.TrademarkDTO;
import com.cskaoyan.mall.product.dto.TrademarkPageDTO;
import com.cskaoyan.mall.product.model.Trademark;
import com.cskaoyan.mall.product.query.TrademarkParam;
import com.cskaoyan.mall.product.service.TrademarkService;
import com.cskaoyan.mall.product.service.impl.TrademarkServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class AdminProductBaseTrademarkController {

    @Autowired
    TrademarkServiceImpl trademarkService;

    @GetMapping("/admin/product/baseTrademark/{pageNo}/{pageSize}")
    public Result<TrademarkPageDTO> getTradeMarkDTOList(@PathVariable Long pageNo, @PathVariable Long pageSize) {
        Page<Trademark> trademarkPage=new Page<>();
        trademarkPage.setCurrent(pageNo);
        trademarkPage.setSize(pageSize);
        TrademarkPageDTO trademarkPageDTOList =trademarkService.getPage(trademarkPage);
        return Result.ok(trademarkPageDTOList);
    }

    @PostMapping("/admin/product/baseTrademark/save")
    public Result save(@RequestBody TrademarkParam trademarkParam){
        trademarkService.save(trademarkParam);
        return Result.ok();
    }

    @DeleteMapping("/admin/product/baseTrademark/remove/{tradeMarkId}")
    public Result deleteById(@PathVariable Long tradeMarkId){
        trademarkService.removeById(tradeMarkId);
        return Result.ok();
    }

    @GetMapping("/admin/product/baseTrademark/get/{tradeMarkId}")
    public Result<TrademarkDTO> getTradeMarkDTO(@PathVariable Long tradeMarkId) {
       TrademarkDTO trademarkDTO = trademarkService.getTrademarkByTmId(tradeMarkId);
        return Result.ok(trademarkDTO);
    }

    @PutMapping("/admin/product/baseTrademark/update")
    public Result updateTradeMark(@RequestBody TrademarkParam trademarkParam){
        trademarkService.updateById(trademarkParam);
        return Result.ok();
    }
}
